package com.mayflygeek.mayflyask.service.impl;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.mayflygeek.mayflyask.common.MailConfigInfo;
import com.mayflygeek.mayflyask.common.MailRegistInfo;
import com.mayflygeek.mayflyask.common.MailResetPasswordInfo;
import com.mayflygeek.mayflyask.service.SendEmailService;
import com.mayflygeek.mayflyask.util.mailutils.MailSenderInfo;
import com.mayflygeek.mayflyask.util.mailutils.SimpleMailSender;
/**
 * @author 蝈蝈 
 * @email guodefu909@126.com
 * @team 蜉蝣极客
 * @link www.mayflygeek.com
 * 发送邮件的服务类
 */
@Service
public class SendEmailServiceImpl implements SendEmailService{
	
	private Logger log = LoggerFactory.getLogger(getClass());

	@Resource
	private MailConfigInfo mailConfigInfo;
	
	@Resource
	private MailRegistInfo mailRegistInfo;
	
	@Resource
	private MailResetPasswordInfo mailResetPasswordInfo;
	
	@Override
	public boolean sendResetPasswordEmail(String userEmail,String resetPasswordUrl){
		log.info("sendResetPasswordEmail");
		String resetPasswordSubject = mailResetPasswordInfo.getResetPasswordSubject();
		String resetPasswordContent = mailResetPasswordInfo.genResetPasswordContent(userEmail, resetPasswordUrl);
		MailSenderInfo mailSenderInfo = new MailSenderInfo();
		mailSenderInfo.setMailConfigInfo(mailConfigInfo);
		mailSenderInfo.setHtmlMail(true);
		mailSenderInfo.setSubject(resetPasswordSubject);
		mailSenderInfo.setContent(resetPasswordContent);
		mailSenderInfo.setToAddress(userEmail);
		
		mailSenderInfo.setDebug(true);
		
		SimpleMailSender.sendMail(mailSenderInfo);
		log.info("userEmail:"+userEmail);
		log.info("resetPasswordSubject:"+resetPasswordSubject);
		log.info("resetPasswordContent:"+resetPasswordContent);
		return false;
		
	}
	
	@Override
	public boolean sendRegistEmail(String userEmail,String registUrl){
		log.info("sendRegistEmail");
		String registSubject = mailRegistInfo.getRegistSubject();
		String registContent = mailRegistInfo.genRegistContent(userEmail, registUrl);
		MailSenderInfo mailSenderInfo = new MailSenderInfo();
		mailSenderInfo.setMailConfigInfo(mailConfigInfo);
		mailSenderInfo.setHtmlMail(true);
		mailSenderInfo.setSubject(registSubject);
		mailSenderInfo.setContent(registContent);
		mailSenderInfo.setToAddress(userEmail);
		
		mailSenderInfo.setDebug(true);
		
		SimpleMailSender.sendMail(mailSenderInfo);
		log.info("toEmail:"+userEmail);
		log.info("registSubject:"+registSubject);
		log.info("registContent:"+registContent);
		return false;
		
	}
	
	
}
